
/*------------------------------------------------------------------------------------*/
// Display message window dynamically
/*------------------------------------------------------------------------------------*/
var toc; //動態建立div的變數
var divid; //div的id
var mouseX   = 0;
var mouseY   = 0;

if( document.layers ) 
{
	document.captureEvents( Event.MOUSEMOVE );
}

document.onmousemove = GetCursor; 

function GetCursor( e ) 
{
	if( document.layers ) 
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	else if( document.all ) 
	{
		mouseX = event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop;
	}
	else if( document.getElementById )
	{
	    mouseX = e.pageX;
		mouseY = e.pageY;
	}
	
	return true;
}

function createLanguageDiv(divID)
{
		var content = "<table width='300' border='0' cellpadding='0' cellspacing='0' background='images/bg_selection.gif' style='border-bottom:1px #999999 solid;border-top:1px #999999 solid;border-right:1px #999999 solid;border-left:1px #999999 solid'>";
		
		content += "<tr><td colspan='4' align='right'><a href='#' onclick='javascript:HideRSSToolTip();'><img src='/images/icon_close.gif' border='0'></a></td></tr>"
		if(typeof(aryLanguage) != "undefined")
		{
			//alert(aryLanguage[0][1]);
			//alert(document.location.pathname);
			for(var i =0; i< aryLanguage.length;i++)
			{
				var strPath = document.location.pathname; //retrieve the URL
				
				if(eval(i+1) % 2 ==1)
				{
					content += "<tr>";
					content +=	"<td width='9' class='list_10bk'>&nbsp;</td>";
					content	+=	"<td width='132' height='27' class='list_10bk'><a href='#' class='menublue' onclick=\"javascript:saveCookie('" + aryLanguage[i][1] + "','" + strPath + "');\">" + aryLanguage[i][0] + "</a></td>";
				}
				else
				{
					content	+=	"<td width='10' class='list_10bk'>&nbsp;</td>";
					content	+=	"<td width='150' height='27' class='list_10bk'><a href='#' class='menublue' onclick=\"javascript:saveCookie('" + aryLanguage[i][1] + "','" + strPath + "');\">" + aryLanguage[i][0] + "</a></td>";
					content += "</tr>"
				}
			}
			
		}
		content += "</table>";
  
		divid = divID;
		removeDiv();
		
		toc = document.createElement("div");
		toc.setAttribute("id", divID);
		var bodyRef = document.getElementsByTagName("body")[0];
		bodyRef.appendChild(toc);
		var objDiv = document.getElementById(divID);
		if(typeof(objDiv) != "undefined")
		{
			objDiv.innerHTML = content;
			//objDiv.mouseOut = HideRSSToolTip();
			objDiv.className = "descDiv";
			objDiv.style.position = "absolute";
			objDiv.style.border = "1 solid #c0c0c0";
			objDiv.style.zIndex = 99;
			objDiv.style.left = mouseX - 150;
			objDiv.style.top = mouseY + 20 ;
			//objDiv.style.display ='none';
		}
}

function showLanguageDiv(divID)
{
	if($('#' + divID).length >0)
	{
		$('#' + divID).css("left",mouseX-150).css("top",mouseY+10).slideDown("fast");
	}
	
}

function hideLanguageDiv(divID)
{
	if($('#' + divID).length >0)
	{
		$('#' + divID).slideUp("fast");
	}

}

function saveCookie(langCode, newUrl, path)
{
	if(langCode)
	{
		var now = new Date();
		set_cookie("GIGABYTEClublangCode",langCode,now.getFullYear()+1,now.getMonth(),now.getDate(),path);
		var strPath = document.URL;
		window.location.href= newUrl;
	}
	else
	{
		alert('cookie name is missing!');
	}
}

function set_cookie (name,value,exp_y,exp_m,exp_d,path,domain,secure)
{
  //delete the previous cookie
  delete_cookie(name);
  var cookie_string = name + "=" + escape(value);
  if(exp_y){
	var expires = new Date(exp_y,exp_m,exp_d);
    cookie_string += "; expires=" + expires.toGMTString();
  }
  if(path){cookie_string += "; path=" + escape(path);}
  if(domain){cookie_string += "; domain=" + escape(domain);}
  if(secure){cookie_string += "; secure";}
  document.cookie = cookie_string;
}

function delete_cookie(cookie_name)
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime(cookie_date.getTime()-1);
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function queryString(key)
{
    var re = new RegExp("[?&]" + key + "=([^&$]*)", "i");
    var offset = location.search.search(re);
    if(offset==-1) return null;
    return RegExp.$1;
}

function HideRSSToolTip()
{
	//var timeid1= window.setInterval(function(){removeDiv(delDiv)},2000);
	window.setTimeout('removeDiv()', 100);
}
function removeDiv()
{
	toc = document.getElementById(divid);
	if(typeof(toc) != "undefined" && typeof(toc) == "object")
	{
		if(toc != null)
		{
			var bodyRef = document.getElementsByTagName("body")[0];
			bodyRef.removeChild(toc);
			//document.body.removeChild(toc);
		}
		
	}
	
}