// Write Flash to pass security check
function writeflash(hyperlink,width,height,channel_id){
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http:\/\/fpdownload.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=8,0,0,0\" width=\"" + width + "\" height=\"" + height + "\">");
    document.write("<param name=\"movie\" value=\"" + hyperlink + "\">");
    document.write("<PARAM NAME=FlashVars VALUE=\"channel_ID=" + channel_id + "\">");
    document.write("<param name=\"quality\" value=\"high\">");
    document.write("<param name=\"menu\" value=\"false\" />");     
	document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\">");
	document.write("<param name=\"wmode\" value=\"transparent\">");
    document.write("<embed src=\"" + hyperlink + "\" FlashVars=\"channel_ID=" + channel_id + "\" quality=\"high\" allowScriptAccess=\"sameDomain\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" wmode=\"transparent\" type=\"application\/x-shockwave-flash\" menu=\"false\" width=\"" + width + "\" height=\"" + height + "\"></embed>");
    document.write("</object>");
}

function writeflash2(hyperlink,width,height,genre_name){
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http:\/\/fpdownload.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=8,0,0,0\" width=\"" + width + "\" height=\"" + height + "\">");
    document.write("<param name=\"movie\" value=\"" + hyperlink + "\">");
    document.write("<PARAM NAME=FlashVars VALUE=\"genre_name=" + genre_name + "\">");
    document.write("<param name=\"quality\" value=\"high\">");
    document.write("<param name=\"menu\" value=\"false\" />");     
	document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\">");
	document.write("<param name=\"wmode\" value=\"transparent\">");
    document.write("<embed src=\"" + hyperlink + "\" FlashVars=\"genre_name=" + genre_name + "\" quality=\"high\" allowScriptAccess=\"sameDomain\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" wmode=\"transparent\" type=\"application\/x-shockwave-flash\" menu=\"false\" width=\"" + width + "\" height=\"" + height + "\"></embed>");
    document.write("</object>");
}

function writeflash3(hyperlink,width,height,channel_id){
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http:\/\/fpdownload.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=8,0,0,0\" width=\"" + width + "\" height=\"" + height + "\">");
    document.write("<param name=\"movie\" value=\"" + hyperlink + "\">");
    document.write("<PARAM NAME=FlashVars VALUE=\"FlashVars=" + channel_id + "\">");
    document.write("<param name=\"quality\" value=\"high\">");
    document.write("<param name=\"menu\" value=\"false\" />");     
	document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\">");
	document.write("<param name=\"wmode\" value=\"transparent\">");
    document.write("<embed src=\"" + hyperlink + "\" FlashVars=\"FlashVars=" + channel_id + "\" quality=\"high\" allowScriptAccess=\"sameDomain\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" wmode=\"transparent\" type=\"application\/x-shockwave-flash\" menu=\"false\" width=\"" + width + "\" height=\"" + height + "\"></embed>");
    document.write("</object>");
}
/* Can preset which promo page to show on the banner space */
function writeflash4(hyperlink,width,height,qs){
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http:\/\/fpdownload.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=8,0,0,0\" width=\"" + width + "\" height=\"" + height + "\">");
    document.write("<param name=\"movie\" value=\"" + hyperlink + "\">");
	document.write("<param name=\"FlashVars\" value='" + qs + "'>");
    document.write("<param name=\"quality\" value=\"high\">");
    document.write("<param name=\"menu\" value=\"false\" />");     
	document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\">");
	document.write("<param name=\"wmode\" value=\"transparent\">");
	document.write("<embed src=\"" + hyperlink + "\" FlashVars='" + qs + "' quality=\"high\" allowScriptAccess=\"sameDomain\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" wmode=\"transparent\" type=\"application\/x-shockwave-flash\" menu=\"false\" width=\"" + width + "\" height=\"" + height + "\"></embed>");
    document.write("</object>");
}
function call_writeflash(hyperlink,channel_id) {
	var width="893";
	var height="380";
	writeflash(hyperlink,width,height,channel_id);
}

// Center Popup window
function popup(width, height, filename, winName)
{
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var attributes = "left=" + left +
	", top=" + top +
	", width=" + width +
	", height=" + height + ", ";
	attributes += "toolbar=0, location=0, directories=0, ";
	attributes += "status=0, menubar=0, scrollbars=1, ";
	attributes += "resizable=1";
	if (winName==''){ winName="fotowin"; }
	window.open(filename, winName, attributes);
}

// Center Popup window without border
function popupwb(width, height, filename)
{
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var attributes = "left=" + left +
	", top=" + top +
	", width=" + width +
	", height=" + height + ", ";
	attributes += "toolbar=0, location=0, directories=0, ";
	attributes += "status=0, menubar=0, scrollbars=0, ";
	attributes += "resizable=1";
	window.open(filename, "fotowin", attributes);
}

function popWin(width, height, filename, winName)
{
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var attributes = "left=" + left +
	", top=" + top +
	", width=" + width +
	", height=" + height + ", ";
	attributes += "toolbar=0, location=0, directories=0, ";
	attributes += "status=0, menubar=0, scrollbars=1, ";
	attributes += "resizable=1";
	window.open(filename, winName, attributes);
}

function getLang() {
	var url = new String(location.href);
	var pos = -1;
	if ((pos = url.indexOf('/eng/')) >= 0) {
		return 'eng';
	} else if ((pos = url.indexOf('/chi/')) >= 0) {
		return 'chi';
	} else {
		return 'eng';
	}
}

function changeLang(toLang) {
	if (toLang == getLang()) return;
	var url = new String(location.href);

	var url2 = '';
	var pos = -1;
	if ((pos = url.indexOf('/eng/')) >= 0) {
		if (pos >= 0) url2 = url.substring(0, pos) + '/chi/' + url.substring(pos + 5, url.length);
	} else if ((pos = url.indexOf('/chi/')) >= 0) {
		if (pos >= 0) url2 = url.substring(0, pos) + '/eng/' + url.substring(pos + 5, url.length);
	}
	if (url2 != '') location.href = url2;
}

// Swap Images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu_bak(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	var url = selObj.options[selObj.selectedIndex].value;
	var firstchar = url.substring(0,1);
	if (firstchar != "/") {
		eval(targ+".location='"+url+"'");
	} else {
		popWin("950", "700", url, "popWin")
	}
	if (restore) selObj.selectedIndex=0;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


function showtable(id) { //v1.0
  document.getElementById(id).style.display="";
}

function hidetable(id) { //v1.0
  document.getElementById(id).style.display="none";
}

/*
  warning pages
*/
function getcookie(name) {
        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) return null;
        if ( start == -1 ) return null;
        var end = document.cookie.indexOf( ";", len );
        if ( end == -1 ) end = document.cookie.length;
        return unescape( document.cookie.substring( len, end ) );
}

function checkWarning() {
	var l = document.location.href;
	var w = 300;
	if (l.indexOf('/900.html') > 0) {
		popupwb(w, w, 'channel/popup_channel/900/warning/warning.html');
		document.location.href = './';
	} else if (l.indexOf('/901.html') > 0) {
		popupwb(w, w, 'channel/popup_channel/901/warning/warning.html');
		document.location.href = './';
	} else if (l.indexOf('/902.html') > 0) {
		popupwb(w, w, 'channel/popup_channel/902/warning/warning.html');
		document.location.href = './';
	} else if (l.indexOf('/903.html') > 0) {
		popupwb(w, w, 'channel/popup_channel/903/warning/warning.html');
		document.location.href = './';
	} else if (l.indexOf('/904.html') > 0) {
		popupwb(w, w, 'channel/popup_channel/904/warning/warning.html');
		document.location.href = './';
	} else if (l.indexOf('/905.html') > 0) {
		popupwb(w, w, 'channel/popup_channel/905/warning/warning.html');
		document.location.href = './';
    } else if (l.indexOf('/genre_adult.html') > 0) {
		if (!getcookie('genre_adult')) {
			popupwb(w, w, 'channel/popup_channel/genre_adult/warning/warning.html');
			document.location.href = './';
		}
	}
}

function promo_startup() {
	var qs = location.search.substring(1);
	var pos = qs.indexOf('.');
	if (pos >= 0) {
		var pdate = qs.substring(0,pos);
		var page = qs.substring(pos+1);
	}
	document.write('<FRAMESET ROWS="*,100%" FRAMEBORDER="0" BORDER="0" FRAMESPACING="0">');
	document.write('<FRAME NAME="t" SRC="" FRAMEBORDER="0" BORDER="0" >');
	document.write('<FRAME NAME="main" SRC="/chi/prom/'+pdate+'/' + page + '.html" FRAMEBORDER="0" BORDER="0" >');
	document.write('</FRAMESET>');
}

function content_startup() {
	var qs = location.search.substring(1);
	var pos = qs.indexOf('.');
	if (pos >= 0) {
		var dir = qs.substring(0,pos);
		var page = qs.substring(pos+1);
	}
	document.write('<FRAMESET ROWS="*,100%" FRAMEBORDER="0" BORDER="0" FRAMESPACING="0">');
	document.write('<FRAME NAME="t" SRC="" FRAMEBORDER="0" BORDER="0" >');
	document.write('<FRAME NAME="main" SRC="/chi/'+dir+'/' + page + '.html" FRAMEBORDER="0" BORDER="0" >');
	document.write('</FRAMESET>');
}

function channel_startup() {
	var qs = location.search.substring(1);
	document.write('<FRAMESET ROWS="*,100%" FRAMEBORDER="0" BORDER="0" FRAMESPACING="0">');
	document.write('<FRAME NAME="t" SRC="" FRAMEBORDER="0" BORDER="0" >');
	document.write('<FRAME NAME="main" SRC="/chi/'+qs+'.html" FRAMEBORDER="0" BORDER="0" >');
	document.write('</FRAMESET>');
}

function promoAd_startup() {
	var qs = location.search.substring(1);
	writeflash4("/common/main_flash/Image/chi/" + qs + ".swf","540","327");
}

function promoSite_startup(id, url) {
	var code = '<img src="/chi_track/promo/'+id+'.track" height=1 width=1>\n';	
	code += '<meta HTTP-EQUIV="refresh" CONTENT="0; URL=' + url + '">\n'; 
	document.write(code);
}

function controlMenuHeight(hh) { 
 var Layer1 = document.getElementById('Layer1');
 if (Layer1 != null) {
	 Layer1.style.clip = "rect(0 1000 "+hh+" 0)"; 
 }
} 


checkWarning();
