/**
  * Copyright 2004 by Hoaphuongnam.com
  * All rights reserved. 
  */
// Constructor: creates a cookie object for the specified doc
function CreateCookie( document, name, hours, path, domain, secure ) {
	// all the predifined properties begin with '$'
	this.$document = document;
	this.$name = name;
	if( hours ) this.$expiration = new Date((new Date()).getTime() + 3600000);
	this.$path = '/';
	if( domain ) this.$domain = domain; else this.$domain = null;
	if( secure ) this.$secure = true; else this.$secure = false;
}

// internal function, never call it explicitly
function _Cookie_store( ) {
	//loop throught the cookie object and get the values of the cookie
	var cookieval = "";
	for( var prop in this ) {
		// ignore properties with names begin with '$' or function
		if( (prop.charAt(0) == '$') || ( (typeof this[prop]) == 'function') ) {
			continue;
		}

		if( cookieval != "" ) cookieval += '&';
			cookieval += prop + ':' + escape( this[prop] );
	}
	// put together a complete cookie string
	var cookie = this.$name + '=' + cookieval;
	if( this.$expiration ) {
		cookie += '; expires=' + this.$expiration.toGMTString();
	}

	if( this.$path ) {
		cookie += '; path=' + this.$path;
	}

	if( this.$secure ) {
		cookie += '; secure';
	}

	// dumping cookie for debugging
	// alert( cookie.length + " chars - " + cookie );
	// now store the cookie
	this.$document.cookie = cookie;
}

// internal function, never call it explicitly
function _Cookie_load( ) {
	// get all cookies pertain to this doc
	var allcookies = this.$document.cookie;
	if( allcookies == "" ) return false;

	// extract just the name cookie in the list
	var start = allcookies.indexOf( this.$name + '=' );
	if( start == -1 ) { return false; }
	start += this.$name.length + 1;
	var end = allcookies.indexOf(';', start);
	if( end == -1 ) end = allcookies.length;
	var cookieval = allcookies.substring( start, end );

	// get value of the named cookie
	var a = cookieval.split( '&' );
	for( var i=0; i<a.length; i++ ) {
		a[i] = a[i].split(':');
	}

	for( var i=0; i<a.length; i++ ) {
		this[a[i][0]] = unescape( a[i][1] );
	}

	// done, return success code
	return true;
}

// internal function, never call it explicitly
function _Cookie_remove( ) {
	var cookie;
	cookie = this.$name + '=';
	if( this.$path ) cookie += '; path=' + this.$path;
	if( this.$domain ) cookie += '; domain=' + this.$domain;
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

	this.$document.cookie = cookie;
}

// Hoaphuongnam radio launch
var winvar = "width=435,height=225,menubar,scrollbars," +
		"location,resizable,status";
function HPNRadio( ) {
	window.open( '/hpnradio.html', 'HPNRadio', winvar );
}

// flash version dectection
var requiredVersion = 5;

var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;
var flash8Installed = false;
var flash9Installed = false;
var maxVersion = 9;
var actualVersion = 0;
var hasRightVersion = false;

// check browser type, do stuff for IE
var isIE = (navigator.userAgent.indexOf("MSIE") < 0 ) ? false : true;
var isWin = (navigator.userAgent.indexOf("Win") < 0 ) ? false : true;

if( isIE && isWin ) {
	document.write('<SCR' + 'IPT LANGUAGE=VBscript\> \n');
	document.write('on error resume next \n');
	document.write('flash2Installed = (NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n actualVersion = 2 \n');
	document.write('flash3Installed = (NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n actualVersion = 3 \n');
	document.write('flash4Installed = (NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n actualVersion = 4 \n');
	document.write('flash5Installed = (NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n actualVersion = 5 \n');
	document.write('flash6Installed = (NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n actualVersion = 6 \n');
	document.write('flash7Installed = (NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n actualVersion = 7 \n');
	document.write('flash8Installed = (NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n actualVersion = 8 \n');
	document.write('flash9Installed = (NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n actualVersion = 9 \n');
	document.write('<\/SCR' + 'IPT\> \n');
}

function detectFlash( ) {
// checking for Opera or non-MSIE browser or not on Windows platform
if ( navigator.userAgent.indexOf("Opera") != -1 || navigator.userAgent.indexOf("MSIE") < 0 || navigator.userAgent.indexOf("Win") < 0 ) {
	var numPlugins = navigator.plugins.length;
	for( var i = 0; i < numPlugins; i++ ) {
		var currentPlugin = navigator.plugins[i];
		if( currentPlugin.name == "Shockwave Flash" ) {
			var flashVersion = currentPlugin.description.match( /[\d+]/ );
			actualVersion = flashVersion;
			break;
		}
	}
}
	if( navigator.userAgent.indexOf("WebTV") != -1 ) actualVersion = 4;

	if( actualVersion >= requiredVersion )  {
		hasRightVersion = true;
	}
}

// detect flash and display appropriate content (i.e: flash image or regular
// image. This function is called from Index.pm module
function displayAoM( id, url, sponsored_by ) {
	detectFlash( ); // detect flash version

	if( hasRightVersion ) {
	var code = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH=436 HEIGHT=227> '
+ '<PARAM NAME=movie VALUE="/aom.swf">'
+ '<PARAM NAME=quality VALUE=high>'
+ '<PARAM NAME=bgcolor VALUE=#FFFFFF>'
+ '<EMBED src="/aom.swf" quality=high bgcolor=#F2E7CC '
+ 'WIDTH=436 HEIGHT=227 TYPE="application/x-shockwave-flash" '
+ 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
+ '<\/EMBED>'
+ '<\/OBJECT><br\/>&nbsp;Bảo trợ bởi <a href="http://' + url + '" class="artisthili"><b>' + sponsored_by + '</b></a>';
	document.writeln( code );
	} else {
	var link = '<table border="0" cellpadding="0" cellspacing="0" width="436"><tbody>'
    + '<tr><td rowspan="3"><a href="/music/search?searchCat=GetArtist&search=186"><img src="/images/aom/aom_01.gif" alt="" border="0" height="227" width="365"></a></td>'
      + '<td colspan="2"> <img src="/images/aom/aom_02.gif" alt="" height="175" width="71"></td></tr>'
    + '<tr><td><a href="http://www.hoaphuongnam.com/downloads/aom.a3u" onMouseOver="playButtonOn( );" onMouseOut="playButtonOff( );"><img name="playButton" src="/images/aom/aom_03.gif" alt="" border="0" height="39" width="41"></a></td>'
      + '<td rowspan="2"> <img src="/images/aom/aom_04.gif" alt="" height="52" width="30"></td></tr>'
    + '<tr><td> <img src="/images/aom/aom_05.gif" alt="" height="13" width="41"></td></tr></tbody></table>'
	+ '<br/>&nbsp;Bảo trợ bởi <a href="http://' + url + '" class="artisthili"><b>' + sponsored_by + '</b></a>';
	document.writeln( link );
	}
}

function playButtonOn( ) {
	document.images['playButton'].src = '/images/aom/play_button_on.gif';
}

function playButtonOff( ) {
	document.images['playButton'].src = '/images/aom/aom_03.gif';
}

function rateOption (help) {
	document.post.helpbox.value = help;
}

function clearRateOption () {
	document.post.helpbox.value = '';
}

// popup user agreement page
function TermsAgreement( ) {
	window.open('/terms.html');
}

var onImages=new Array();
<!--
if (parent.frames.length > 0) {
	parent.location.href = self.document.location
}
//-->
function Rollover(imgName, imgSrc)
{
	onImages[imgName] = new Image();
	onImages[imgName].src = imgSrc;
}
function turnOn(imgName, text) 
{ 
	//if(document.images[imgName].filters != null)
	//	document.images[imgName].filters[0].stop();
	document.images[imgName].offSrc = document.images[imgName].src;

	if( imgName == "tstar" ) {
	document.images['ostar'].offSrc = document.images['ostar'].src;
	document.images['ostar'].src    = onImages['ostar'].src;
	} else
	if( imgName == "trstar" ) {
	document.images['ostar'].offSrc = document.images['ostar'].src;
	document.images['tstar'].offSrc = document.images['tstar'].src;
	document.images['ostar'].src    = onImages['ostar'].src;
	document.images['tstar'].src    = onImages['tstar'].src;
	} else
	if( imgName == "fstar" ) {
	document.images['ostar'].offSrc = document.images['ostar'].src;
	document.images['tstar'].offSrc = document.images['tstar'].src;
	document.images['trstar'].offSrc = document.images['trstar'].src;
	document.images['ostar'].src    = onImages['ostar'].src;
	document.images['tstar'].src    = onImages['tstar'].src;
	document.images['trstar'].src    = onImages['trstar'].src;
	} else
	if( imgName == "fvstar" ) {
	document.images['ostar'].offSrc = document.images['ostar'].src;
	document.images['tstar'].offSrc = document.images['tstar'].src;
	document.images['trstar'].offSrc = document.images['trstar'].src;
	document.images['fstar'].offSrc = document.images['fstar'].src;
	document.images['ostar'].src    = onImages['ostar'].src;
	document.images['tstar'].src    = onImages['tstar'].src;
	document.images['trstar'].src    = onImages['trstar'].src;
	document.images['fstar'].src    = onImages['fstar'].src;
	}
	document.images[imgName].src    = onImages[imgName].src;
} 
function turnOff(imgName) 
{ 
	//if(document.images[imgName].filters != null)
        //document.images[imgName].filters[0].apply();
	document.images[imgName].src = document.images[imgName].offSrc;
	document.images['ostar'].src = "/icons/rstar.gif"; 
	document.images['tstar'].src = "/icons/rstar.gif";
	document.images['trstar'].src = "/icons/rstar.gif";
	document.images['fstar'].src = "/icons/rstar.gif";
	document.images['fvstar'].src = "/icons/rstar.gif";

	//if(document.images[imgName].filters != null)
	//	document.images[imgName].filters[0].play();
} 
Rollover("ostar", "/icons/star.gif");
Rollover("tstar", "/icons/star.gif");
Rollover("trstar", "/icons/star.gif");
Rollover("fstar", "/icons/star.gif");
Rollover("fvstar", "/icons/star.gif");
