﻿/* Object retrieval */
function getAll(ID)
{	var els=[];
	var tags;

	if (document.all)
		tags = document.all;
	else if (document.getElementsByTagName) tags =document.getElementsByTagName('*');
	for(var i=0;i < tags.length;i++)
	{	if(tags[i].id==ID)
			els[els.length]=tags[i];
	}
	return els;
}

// auxiliary function
function get(divID)
{	if (document.all)
		return document.all[divID];
	else if (document.getElementById)
		return document.getElementById(divID);
	else return null;
}

/* Object Manipulation */
/* Use the visibility property.  Less expensive, but still occupies space unless object is positioned as absolute */
 
function show(obj)
{	if (document.layers)
		obj.visibility = "show";
   	else
		obj.style.visibility = "visible";
}

function hide(obj)
{   	if (document.layers) obj.visibility="hide";
      		else obj.style.visibility="hidden";
}

/* Use the display property.  More expensive, and not compatible with Netscape 4 */
function display(obj)
{	obj.style.display="block";}

function noDisplay(obj)
{		obj.style.display="none";	}

function toggleDisplay(obj)
{	if (isDisplayed(obj))
		noDisplay(obj);
	else display(obj);
}

function isDisplayed(obj)
{	return (obj.style.display!="none");
}

function move(obj, x,y)
{	if (document.layers)
	{	obj.left = x;
		obj.top = y;   	}
   	else
   	{	obj.style.pixelLeft = x;
		obj.style.pixelTop = y;	}
}

function addBookmark(title,url)
{	if( document.all )
		window.external.AddFavorite(url, title);
	else if (window.sidebar) 
		window.sidebar.addPanel(title, url,""); 
	else return false;
}

/* Cookie Manipulation */
function setCookie( name, value, expires, domain, path, secure)
{
	var cstr = escape(name)+ "="+ escape(value);
	if (expires>0)
	{
		var expdate = new Date();
		expdate.setTime(expdate.getTime() + (expires*60*60*24*1000));
		expdate = expdate.toGMTString();
		cstr+="; expires="+ expdate;
	}
	
	if (domain) cstr+="; domain ="+domain;
	if (path) cstr+="; path ="+path;
	if (secure) cstr+="; secure";

	document.cookie = cstr;
}

function getCookie(cookieName) 
{
	var theCookie=""+document.cookie;
 	var ind=theCookie.indexOf(cookieName);
 	if (ind==-1 || cookieName=="")
	 	return null;
 	var ind1=theCookie.indexOf(';',ind);
 	if (ind1==-1)
	 	ind1=theCookie.length;
 	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

// Change Display Name //

function ShowInput() {
	display(get('change-name'));
	noDisplay(get('user-info'));
}

function HideInput() {
	display(get('user-info'));
	noDisplay(get('change-name'));
}


// Show Pop Up

function getPosTop(obj)
{
	var top = isNaN(obj.offsetTop ) ?  0 : obj.offsetTop;
	if ( obj.offsetParent != null ){ top += getPosTop(obj.offsetParent); }
	return top;
}

function getPosLeft(obj)
{
	var left = isNaN(obj.offsetLeft ) ?  0 : obj.offsetLeft;
	if ( obj.offsetParent != null ){left += getPosLeft(obj.offsetParent); }
	return left;
}

function ShowLayer(btn,opt)
{
	var root_obj = document.getElementById(btn);
	var menu_obj = document.getElementById(opt);

	menu_obj.style.top = getPosTop(root_obj) + 'px';
	menu_obj.style.left = getPosLeft(root_obj) + 'px';
	
	menu_obj.style.display = "block";
}


function HideLayer(opt) {
	var menu_obj = document.getElementById(opt);
	menu_obj.style.display = "none";
}

function ShowOSA(btn,opt)
{
	var root_obj = document.getElementById(btn);
	var menu_obj = document.getElementById(opt);

	menu_obj.style.top = getPosTop(root_obj) +80 + 'px';
	menu_obj.style.left = getPosLeft(root_obj) +165 + 'px';
	
	menu_obj.style.display = "block";
}

function ShowSoftware(btn,opt)
{
	var root_obj = document.getElementById(btn);
	var menu_obj = document.getElementById(opt);

	menu_obj.style.top = getPosTop(root_obj) +168 + 'px';
	menu_obj.style.left = getPosLeft(root_obj) +61 + 'px';
	
	menu_obj.style.display = "block";
}

function ShowSeed(btn,opt)
{
	var root_obj = document.getElementById(btn);
	var menu_obj = document.getElementById(opt);

	menu_obj.style.top = getPosTop(root_obj) +282 + 'px';
	menu_obj.style.left = getPosLeft(root_obj) +165 + 'px';
	
	menu_obj.style.display = "block";
}

function ShowStation(btn,opt)
{
	var root_obj = document.getElementById(btn);
	var menu_obj = document.getElementById(opt);

	menu_obj.style.top = getPosTop(root_obj) +213 + 'px';
	menu_obj.style.left = getPosLeft(root_obj) +326 + 'px';
	
	menu_obj.style.display = "block";
}

function ShowNetwork(btn,opt)
{
	var root_obj = document.getElementById(btn);
	var menu_obj = document.getElementById(opt);

	menu_obj.style.top = getPosTop(root_obj) +200 + 'px';
	menu_obj.style.left = getPosLeft(root_obj) +179 + 'px';
	
	menu_obj.style.display = "block";
}

function contact_check()
{
    var filter  = /^[0-9]*[0-9]$/;

    var subject = window.document.getElementById("subject_err");
    var from = window.document.getElementById("from_err");
    var org = window.document.getElementById("org_err");
    var phone = window.document.getElementById("phone_err");
    var message = window.document.getElementById("message_err");

    if (window.document.contact.subject.value == "")
    {
        subject.style.display = "";
        return false;
    }
    subject.style.display = "none";

    if ((window.document.contact.from.value == "") ||
       (window.document.contact.from.value.indexOf('@') == -1))
    {
        from.style.display = "";
        return false;
    }
    from.style.display = "none";

    if (window.document.contact.org.value == "")
    {
        org.style.display = "";
        return false;
    }
    org.style.display = "none";

    if ((window.document.contact.phone.value == "") ||
        (filter.test(window.document.contact.phone.value) == false))
    {
        phone.style.display = "";
        return false;
    }
    phone.style.display = "none";

    if (window.document.contact.message.value == "")
    {
        message.style.display = "";
        return false;
    }
    message.style.display = "none";

    return true;
}

// Change Language //
function changeLanguage(lang) {	
  myurl = document.location.href;
  end = (myurl.indexOf("?") == -1) ? myurl.length : myurl.indexOf("?");    
  current_lang = "/en/";
  if (myurl.lastIndexOf("/en/") > 0) {
  	current_lang = "/en/";
  } else if (myurl.lastIndexOf("/tw/") > 0) {
    current_lang = "/tw/";
  } else {
  	current_lang = "/cn/";
  }  
  url_head = myurl.substring(0, myurl.lastIndexOf(current_lang));
  url_tail = myurl.substring(myurl.lastIndexOf(current_lang)+4, end);
  destination = url_head + "/" + lang + "/" + url_tail  

  location.href= destination;    
}


function twBottomNav() {
  myurl=document.location.href.split("/");
  x=myurl.length-2;
  y=myurl.length-1;
  e = document.getElementById('bottom-nav');
  e.className='tw';
  if (myurl[x]=='company') {
	e.innerHTML ="<li><a href=\"about.html\">關於我們</a></li><li><a href=\"contact.html\">聯絡我們</a></li><li><a href=\"http://contest2008.teltel.com\" target=\"_blank\">創意大賽</a></li><li><a href=\"news.html\">最新訊息</a></li>";
  } else {
	e.innerHTML ="<li><a href=\"../company/about.html\">關於我們</a></li><li><a href=\"../company/contact.html\">聯絡我們</a></li><li><a href=\"http://contest2008.teltel.com\" target=\"_blank\">創意大賽</a></li><li><a href=\"../company/news.html\">最新訊息</a></li>";
  }
  
  if (myurl[y]=='news.html') {
	e.innerHTML ="<li><a href=\"about.html\">關於我們</a></li><li><a href=\"contact.html\">聯絡我們</a></li><li><a href=\"http://contest2008.teltel.com\" target=\"_blank\">創意大賽</a></li><li><a href=\"news.html\" class=\"on\">最新訊息</a></li>";
  }
  
  if (myurl[y]=='about.html'|| myurl[y]=='bios.html') {
	e.innerHTML ="<li><a href=\"about.html\" class=\"on\">關於我們</a></li><li><a href=\"contact.html\">聯絡我們</a></li><li><a href=\"http://contest2008.teltel.com\" target=\"_blank\">創意大賽</a></li><li><a href=\"news.html\">最新訊息</a></li>";
  }
  
  if (myurl[y]=='contact.html') {
	e.innerHTML ="<li><a href=\"about.html\" >關於我們</a></li><li><a href=\"contact.html\" class=\"on\">聯絡我們</a></li><li><a href=\"http://contest2008.teltel.com\" target=\"_blank\">創意大賽</a></li><li><a href=\"news.html\">最新訊息</a></li>";
  }
  
}

window.onload=function() {
  myurl=document.location.href.split("/");
  t=myurl.length-3;
  if(myurl[t]=='tw') {
   twBottomNav();
  }
}