/* internet TV faq answer show & hide function */
function answerOpen(num,totalnum) {
	chbgicon = document.getElementById('q'+num);
	if (document.getElementById('answer'+num).style.display=='none') {		
		document.getElementById('answer'+num).style.display='block';
		chbgicon.className = "questionconton";
		for (i = 1; i < totalnum; i++) {
			chbgicon = document.getElementById('q'+i);
			if (num == i) {		
				document.getElementById('answer'+i).style.display='block';
				var contme = chbgicon.parentNode;
				chbgicon.className = "questionconton";
			} else {
				document.getElementById('answer'+i).style.display='none';
				var contme = chbgicon.ChideNodes;
				chbgicon.className = "questioncont";
			}
		}
	}
	 else {
		document.getElementById('answer'+num).style.display='none';
		chbgicon.className = "questioncont";
	}
}

/* flash insert */
function flashCM(URL,width,height,vars,bgColor,winmode, id) {

	var id=URL.split("/")[URL.split("/").length-1].split(".")[0];
	if(vars==null) vars='';
	if(bgColor==null) bgColor='transparent';
	if(winmode==null) winmode='opaque';

	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' "); 
	document.write("		width='"+width+"' height='"+height+"' id='"+id+"' align='middle'> ");
	document.write("	<param name='allowScriptAccess' value='always' /> ");
	document.write("	<param name='movie' 						value='"+URL+"' /> ");
	document.write("	<param name='FlashVars' 				value='"+vars+"' /> ");
	document.write("	<param name='wmode' 						value='"+winmode+"' /> ");
	document.write("	<param name='menu' 							value='false' /> ");
	document.write("	<param name='quality'						value='high' /> ");
	document.write("	<param name='bgcolor'						value='"+bgColor+"' /> ");
	document.write("	<embed src='"+URL+"' flashVars='"+vars+"' wmode='"+winmode+"' menu='false' quality='high' ");
	document.write("		bgcolor='"+bgColor+"' width='"+width+"' height='"+height+"' name='"+id+"' align='middle' ");
	document.write("		allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /> ");
	document.write("	</object> ");
}

/*popup*/
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
	var LeftPosition=0;
	var TopPosition=0;
	if(pos=="random"){
		LeftPosition=(screen.width) ? Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height) ? Math.floor(Math.random()*((screen.height-h)-75)):100;
	} else if(pos=="center"){
		LeftPosition=(screen.width) ? (screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
	} else {
		LeftPosition=0;
		TopPosition=20;
	}
	LeftPosition=parseInt(LeftPosition);
	TopPosition=parseInt(TopPosition);
	// for IE
	if((navigator.appVersion.indexOf("MSIE") != -1) ? true : false){
		//h=h+35;
		h=Number(h)+35;
	}
	var settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
	if (win==null)
	{ 
		if (navigator.appVersion.indexOf("MSIE") != -1)
		{
			viewlayer('winalert_layer','on')
		}		
	}
}
 
// content library flash faq answer show & hide function 
function answerOpenlib(num,totalnum) {
	chbgicon = document.getElementById('q'+num);
	if (document.getElementById('answer'+num).style.display=='none') {		
		document.getElementById('answer'+num).style.display='block';
		chbgicon.className = "questioncontonlib";
		for (i = 1; i < totalnum; i++) {
			chbgicon = document.getElementById('q'+i);
			if (num == i) {		
				document.getElementById('answer'+i).style.display='block';
				var contme = chbgicon.parentNode;
				chbgicon.className = "questioncontonlib";
			} else {
				document.getElementById('answer'+i).style.display='none';
				var contme = chbgicon.ChideNodes;
				chbgicon.className = "questioncont";
			}
		}
	}
	 else {
		document.getElementById('answer'+num).style.display='none';
		chbgicon.className = "questioncont";
	}
}

// usb 2.0 movie answer show & hide function
function answerOpenusb(num,totalnum) {
	chbgicon = document.getElementById('q'+num);
	if (document.getElementById('answer'+num).style.display=='none') {		
		document.getElementById('answer'+num).style.display='block';
		chbgicon.className = "questioncontonusb";
		for (i = 1; i < totalnum; i++) {
			chbgicon = document.getElementById('q'+i);
			if (num == i) {		
				document.getElementById('answer'+i).style.display='block';
				var contme = chbgicon.parentNode;
				chbgicon.className = "questioncontonusb";
			} else {
				document.getElementById('answer'+i).style.display='none';
				var contme = chbgicon.ChideNodes;
				chbgicon.className = "questioncont";
			}
		}
	}
	 else {
		document.getElementById('answer'+num).style.display='none';
		chbgicon.className = "questioncont";
	}
}

// DLNA Wireless faq answer show & hide function 
function answerOpenwire(num,totalnum) {
	chbgicon = document.getElementById('q'+num);
	if (document.getElementById('answer'+num).style.display=='none') {		
		document.getElementById('answer'+num).style.display='block';
		chbgicon.className = "questioncontonwire";
		for (i = 1; i < totalnum; i++) {
			chbgicon = document.getElementById('q'+i);
			if (num == i) {		
				document.getElementById('answer'+i).style.display='block';
				var contme = chbgicon.parentNode;
				chbgicon.className = "questioncontonwire";
			} else {
				document.getElementById('answer'+i).style.display='none';
				var contme = chbgicon.ChideNodes;
				chbgicon.className = "questioncont";
			}
		}
	}
	 else {
		document.getElementById('answer'+num).style.display='none';
		chbgicon.className = "questioncont";
	}
}

function addLoadEvent(func){
 var oldonload = window.onload;
 if(typeof window.onload != 'function'){
  window.onload = func;
 }
 else {
  window.onload = function(){
   oldonload();
   func();
  }
 }
} 

function selTab(){
	var tabyear = document.getElementById("tabyear");
	var choiceyear = tabyear.getElementsByTagName("li");
	choiceyear[0].className = "on";
	for (i=0; i<choiceyear.length ; i++)
	{
		choiceyear[i].style.cursor = "pointer";
		var chyear = choiceyear[0];
		var chold = choiceyear[1];
		var year0 = document.getElementById("year0")
		var year1 = document.getElementById("year1")
		chyear.onclick = function(){
			chyear.className = "on"; chold.className = "";
			year1.style.display = "none"; year0.style.display = "";
			categoryView("0");
		}
		chold.onclick = function(){
			chold.className = "on";	chyear.className = "";
			year0.style.display = "none"; year1.style.display = "";
			categoryViewUp("0");
		}
	}
}

// select download category 
function categoryView(num) {
  var gallery = document.getElementById("gallery");
  var cooking = document.getElementById("cooking");
  var game = document.getElementById("game");
  var children = document.getElementById("children");
  var wellness = document.getElementById("wellness");
  var other = document.getElementById("other");
  var sorttab = document.getElementById("sorttab");
  var sorttabcount = sorttab.getElementsByTagName("li");
  for (i=0; i<sorttabcount.length; i++ )
  {
	 if (num==i) {sorttabcount[i].className = "chtabtxt";}
	 else {sorttabcount[i].className = "";}
  }

  if(num == "0") {
    gallery.style.display = "block" ;
    cooking.style.display = "block" ;
//    game.style.display = "block" ;
    children.style.display = "block" ;
    wellness.style.display = "block" ;
//    other.style.display = "block" ;
  } else if(num == "1") {
    gallery.style.display = "block" ;
    cooking.style.display = "none" ;
    game.style.display = "none" ;
    children.style.display = "none" ;
    wellness.style.display = "none" ;
    other.style.display = "none" ;
  } else if(num == "2") {
    gallery.style.display = "none" ;
    cooking.style.display = "block" ;
    game.style.display = "none" ;
    children.style.display = "none" ;
    wellness.style.display = "none" ;
    other.style.display = "none" ;
  } else if(num == "3") {
    gallery.style.display = "none" ;
    cooking.style.display = "none" ;
    game.style.display = "none" ;
    children.style.display = "block" ;
    wellness.style.display = "none" ;
    other.style.display = "none" ;
  } else if(num == "4") {
    gallery.style.display = "none" ;
    cooking.style.display = "none" ;
    game.style.display = "none" ;
    children.style.display = "none" ;
    wellness.style.display = "block" ;
    other.style.display = "none" ;
  } else if(num == "5") {
    gallery.style.display = "none" ;
    cooking.style.display = "none" ;
    game.style.display = "none" ;
    children.style.display = "none" ;
    wellness.style.display = "block" ;
    other.style.display = "none" ;
  } else if(num == "6") {
    gallery.style.display = "none" ;
    cooking.style.display = "none" ;
    game.style.display = "none" ;
    children.style.display = "none" ;
    wellness.style.display = "none" ;
    other.style.display = "block" ;
  } 
}

function categoryViewUp(num) {
  var gallery = document.getElementById("gallery1");
  var cooking = document.getElementById("cooking1");
  var game = document.getElementById("game1");
  var children = document.getElementById("children1");
  var wellness = document.getElementById("wellness1");
  var other = document.getElementById("other1");
  var sorttab = document.getElementById("sorttab1");
  var sorttabcount = sorttab.getElementsByTagName("li");
  for (i=0; i<sorttabcount.length; i++ )
  {
	 if (num==i) {sorttabcount[i].className = "chtabtxt";}
	 else {sorttabcount[i].className = "";}
  }

  if(num == "0") {
    gallery1.style.display = "block" ;
    cooking1.style.display = "block" ;
//    game1.style.display = "block" ;
    children1.style.display = "block" ;
    wellness1.style.display = "block" ;
//    other1.style.display = "block" ;
  } else if(num == "1") {
    gallery1.style.display = "block" ;
    cooking1.style.display = "none" ;
    game1.style.display = "none" ;
    children1.style.display = "none" ;
    wellness1.style.display = "none" ;
    other1.style.display = "none" ;
  } else if(num == "2") {
    gallery1.style.display = "none" ;
    cooking1.style.display = "block" ;
    game1.style.display = "none" ;
    children1.style.display = "none" ;
    wellness1.style.display = "none" ;
    other1.style.display = "none" ;
  } else if(num == "3") {
    gallery1.style.display = "none" ;
    cooking1.style.display = "none" ;
    game1.style.display = "none" ;
    children1.style.display = "block" ;
    wellness1.style.display = "none" ;
    other1.style.display = "none" ;
  } else if(num == "4") {
    gallery1.style.display = "none" ;
    cooking1.style.display = "none" ;
    game1.style.display = "none" ;
    children1.style.display = "none" ;
    wellness1.style.display = "block" ;
    other1.style.display = "none" ;
  } else if(num == "5") {
    gallery1.style.display = "none" ;
    cooking1.style.display = "none" ;
    game1.style.display = "none" ;
    children1.style.display = "none" ;
    wellness1.style.display = "block" ;
    other1.style.display = "none" ;
  } else if(num == "6") {
    gallery1.style.display = "none" ;
    cooking1.style.display = "none" ;
    game1.style.display = "none" ;
    children1.style.display = "none" ;
    wellness1.style.display = "none" ;
    other1.style.display = "block" ;
  } 
}

// download preview
var MEDI_cnt = 0;
function layertest(event,addr,type,title,c1,c2,c3,c4,c5)
{
	var a = document.getElementById('MEDI_f');
	var b = document.getElementById('MEDI_C');
	var c = document.getElementById('MEDI_l');
	var d = document.getElementById('MEDI_a');
	
	a.style.position = "absolute";
	a.style.top = "-4px";
	a.style.left = "-21px";
	a.style.height = win.getScrollHeight()+"px";
	a.style.width = win.getScrollWidth()+"px";

	if(addr) {
		a.style.top = 0;
		a.style.left = 0;
		a.style.display = "";
		
		if (type == 'download') {
			var layerflash
			layerflash = '';
			layerflash += '<table id="MEDI_frame" cellpadding="0" cellspacing="0" border="0">';
			layerflash += '<tr>';
			layerflash += '<td>';
				layerflash += '<div id="mommy" class="downloadlayer">';
					layerflash += '<div class="topclose"><a href="#" onclick="javascript:layertest();"><img src="images/common/btn_close.gif"></a></div>';
					layerflash += '<p class="downloadtxt blackcolor b mgt15">Select your language</p>';
					layerflash += '<ul id="existfile" class="downloadlang">';
						layerflash += '<li class="hangover">- <a href="#" onclick="javascript:layertest(event,\'okdown\',\'okdownload\',\'title\',\''+c1+'\'); return false">North America / Latin America</a></li>';
						layerflash += '<li class="hangover">- <a href="#" onclick="javascript:layertest(event,\'okdown\',\'okdownload\',\'title\',\''+c2+'\'); return false">Europe / CIS</a></li>';
						layerflash += '<li class="hangover">- <a href="#" onclick="javascript:layertest(event,\'okdown\',\'okdownload\',\'title\',\''+c3+'\'); return false">South East Asia / China / Taiwan / Hong Kong</a></li>';
						layerflash += '<li class="hangover">- <a href="#" onclick="javascript:layertest(event,\'okdown\',\'okdownload\',\'title\',\''+c4+'\'); return false">Middle East Asia</a></li>';
						layerflash += '<li class="hangover">- <a href="#" onclick="javascript:layertest(event,\'okdown\',\'okdownload\',\'title\',\''+c5+'\'); return false">Brazil</a></li>';
					layerflash += '</ul>';
				layerflash += '</div>';
			layerflash += '</td>';
			layerflash += '</tr>';
			layerflash += '</table>';
			b.innerHTML = layerflash;
			if(arguments[2]) b.onclick = '';
			var existfile = document.getElementById("existfile");
			var filelist = existfile.getElementsByTagName("li");
			var linklist = existfile.getElementsByTagName("a");

			for (i=0; i<filelist.length ; i++)
			{
				if (arguments[i+4]) {	
					filelist[i].className = "filex";
				}  
				else {
					linklist[i].setAttribute("onclick", "");
				}
			}
			STmedi_setdown(event,b,true); 

		}
		else if (type == 'okdownload') {
			var layerflash;
//			var linkurl = "http://www.samsung.com/global/products/tv/contents_lib/";
			layerflash = '';
			layerflash += '<table id="MEDI_frame" cellpadding="0" cellspacing="0" border="0">';
			layerflash += '<tr>';
			layerflash += '<td align="center">';
				layerflash += '<div class="okdownlayer">';
					layerflash += '<p class="blackcolor mgt15">下載後，請在連接電視機前<br />把文件解壓縮到USB中。</p>';
					layerflash += '<div style="padding:15px 8px 15px 8px;"><a href="'+c1+'" onclick="goDownload(this); return true"><img src="images/common/btn_ok.gif" alt="立即下载" /></a> <a href="#" onclick="javascript:layertest();"><img src="images/common/btn_cancel.gif" alt="取消" /></a></div>';					
				layerflash += '</div>';
			layerflash += '</td>';
			layerflash += '</tr>';
			layerflash += '</table>';
			b.innerHTML = layerflash;
			if(arguments[2]) b.onclick = '';
			STmedi_setokdown(event,b,true); 
		}
		else if (type == 'preview') {
			var layerflash;
			layerflash = '';
			layerflash += '<table id="MEDI_frame" cellpadding="0" cellspacing="0" border="0">';
			layerflash += '<tr>';
			layerflash += '<td>';
				layerflash += '<div class="previewlayer">';
					layerflash += '<div class="topclose2"><a href="#" onclick="javascript:layertest();"><img src="images/common/btn_close.gif" alt="close" style="margin:3px 5px 0 0" /></a></div>';
					layerflash += '<img src="images/common/'+title+'" alt="" style="padding:8px 8px 0 8px;" />';
					layerflash += '<div class="textc"><a href="#" onclick="javascript:layertest(event,\'down\',\'download\',\'title\',\''+c1+'\',\''+c2+'\',\''+c3+'\',\''+c4+'\',\''+c5+'\');"><img src="images/common/btn_download.gif" alt="download" style="padding:8px" /></a></div>';					
				layerflash += '</div>';
			layerflash += '</td>';
			layerflash += '</tr>';
			layerflash += '</table>';
			b.innerHTML = layerflash;
			if(arguments[2]) b.onclick = '';
			STmedi_setpreview(event,b,true); 
		} 
		else if (type == 'previewold') {
			var layerflash;
//			var linkurl = "http://www.samsung.com/global/products/tv/contents_lib/";
			layerflash = '';
			layerflash += '<table id="MEDI_frame" cellpadding="0" cellspacing="0" border="0">';
			layerflash += '<tr>';
			layerflash += '<td>';
				layerflash += '<div class="previewlayer">';
					layerflash += '<div class="topclose2"><a href="#" onclick="javascript:layertest();"><img src="images/common/btn_close.gif" alt="close" style="margin:3px 5px 0 0" /></a></div>';
					layerflash += '<img src="images/common/'+title+'" alt="" style="padding:8px 8px 0 8px;" />';
					layerflash += '<div class="textc"><a href="#" onclick="javascript:layertest(event,\'okdown\',\'okdownload\',\'title\',\''+linkurl+c1+'\',\''+linkurl+c2+'\',\''+linkurl+c3+'\',\''+linkurl+c4+'\',\''+linkurl+c5+'\');"><img src="images/common/btn_download.gif" alt="download" style="padding:8px" /></a></div>';					
				layerflash += '</div>';
			layerflash += '</td>';
			layerflash += '</tr>';
			layerflash += '</table>';
			b.innerHTML = layerflash;
			if(arguments[2]) b.onclick = '';
			STmedi_setpreview(event,b,true); 
		} else if (type='html'){
			b.innerHTML = addr;
			STmedi_setpreview(b.firstChild);
			if(arguments[2]) b.onclick = '';
		}

	} else {
		a.onclick = '';
		if(d.style.display != "")
		{
			a.style.display = "none";
			a.style.height = '100%';
			a.style.width = '100%';
		}
		b.innerHTML = "";
		b.onclick = function () { layertest() };
		c.style.display = "none";
		a.style.zIndex = "9995";
		d.style.zIndex = "9998";
		MEDI_cnt = 0;
	}
}

function goDownload(obj){
	location.href = obj; layertest();
}

function STmedi_setdown(evt,obj) {
	if (obj) {
		var e = evt || window.event;
		var scrollh = document.documentElement.scrollTop;
		var positionX = e.clientX-80;
		var positionY = (e.clientY+scrollh)-100;
		var setdown = document.getElementById('MEDI_C');
		var wrap = document.getElementById("wrap");
		setdown.style.left = positionX+"px";
		setdown.style.top = positionY+"px";
		obj.style.visibility = 'visible';
	}
}

function STmedi_setokdown(evt,obj) {
	if (obj) {
		var e = evt || window.event;
		var scrollh = document.documentElement.scrollTop;
		var positionX = e.clientX-90;
		var positionY = (e.clientY+scrollh)-50;
		var setdownok = document.getElementById('MEDI_C');
		setdownok.style.left = positionX+"px";
		setdownok.style.top = positionY+"px";
		obj.style.visibility = 'visible';
	}
}

function STmedi_setpreview(evt,obj) {
	if (obj) {
		var e = evt || window.event;
		var scrollh = document.documentElement.scrollTop;
		var positionX = e.clientX/1.5;
		var positionY = (e.clientY+scrollh)/1.2;
		var setpreview = document.getElementById('MEDI_C');
		setpreview.style.left = positionX+"px";
		setpreview.style.top = positionY+"px";
		obj.style.visibility = 'visible';
	}
}


var win ={
	getWidth: function(){
		if (document.childNodes && !document.all && !navigator.taintEnabled) return window.innerWidth;
		if (window.opera) return document.body.clientWidth;
		return document.documentElement.clientWidth;
	},

	getHeight: function(){
		if (document.childNodes && !document.all && !navigator.taintEnabled) return window.innerHeight;
		if (window.opera) return document.body.clientHeight;
		return document.documentElement.clientHeight;
	},

	getScrollWidth: function(){
		if (window.ActiveXObject) return Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
		if (document.childNodes && !document.all && !navigator.taintEnabled) return document.body.scrollWidth;
		return document.documentElement.scrollWidth;
	},

	getScrollHeight: function(){
		if (window.ActiveXObject) return Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
		if (document.childNodes && !document.all && !navigator.taintEnabled) return document.body.scrollHeight;
		return document.documentElement.scrollHeight;
	},

	getScrollLeft: function(){
		return window.pageXOffset || document.documentElement.scrollLeft;
	},

	getScrollTop: function(){
		return window.pageYOffset || document.documentElement.scrollTop;
	},
	getPosition: function(){return {'x': 0, 'y': 0}}

};
