var agt=navigator.userAgent.toLowerCase();
var is_safari = agt.indexOf("safari")!=-1;
var ie = (navigator.appName=="Microsoft Internet Explorer");

function navMenu(flag, n, l, t) {
    var menuflag;
    var name;
    var left;
    var top;

    this.menuflag = flag;
    this.name = n;
    this.left = l;
    this.top = t;
    this.openmenu =OpenMenu;
    this.closemenu =CloseMenu;
    this.oldmenu ="";

    function OpenMenu()
    {
       if( !this.menuflag ){
          var obj = document.getElementById(this.name);
	  	  /*obj.style.visibility="visible";
          obj.style.position="absolute";*/
          obj.style.display="block";
          obj.style.left = this.left;
          obj.style.top = this.top;
          this.menuflag = true;
       } else {
		   this.closemenu();
       }
    }

	function CloseMenu()
	{
     	var obj = document.getElementById(this.name);
     	/*obj.style.visibility="hidden";
     	obj.style.position="absolute";*/
        obj.style.display="none";
     	this.menuflag = false;
	}
}

function closemenu(menustr)
{
   var index = -1;
   
   for( i=0; i<navMenuArray.length; i++ )
	   if( navMenuArray[i].name == menustr ) index = i;

   navMenuArray[index].closemenu();

   for( i=0; i<navMenuArray.length; i++ )
	   navMenuArray[i].oldmenu = "";
}

function openmenu(menustr)
{
   var index = -1;
   
   for( i=0; i<navMenuArray.length; i++ )
	   if( navMenuArray[i].name == menustr ) index = i;

   if( navMenuArray[index].oldmenu!=""&& navMenuArray[index].oldmenu!=navMenuArray[index].name) 
	   closemenu(navMenuArray[index].oldmenu);

   //alert(navMenuArray[index].menuflag);

   navMenuArray[index].openmenu();

   for( i=0; i<navMenuArray.length; i++ )
	   navMenuArray[i].oldmenu = menustr;
}

function chgDiv(objstr) {
  divarray = new Array('tech', 'prof', 'serv');

  for( i in divarray ) {
      //if( divarray[i] == objstr ) continue;
      objtemp = document.getElementById(divarray[i]);
      /*objtemp.style.visibility = 'hidden';
      objtemp.style.position = 'absolute';*/
      objtemp.style.display = 'none';
  }

  obj = document.getElementById(objstr);

  /*if( obj.style.visibility == 'hidden' || obj.style.visibility=="" ) {
      obj.style.visibility = 'visible';
      obj.style.position = 'static';
  } else {
      obj.style.visibility = 'hidden';
      obj.style.position = 'absolute';
  }*/
  if( obj.style.display == 'none' || obj.style.visibility=="" ) {
      obj.style.display = 'block';
  } else {
      obj.style.display = 'none';
  }
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function bgClear( menustr, act )
{
	var obj;
	var tdstr=menustr.replace(/menu/, 'img');
	if( (obj=findDiv(menustr))!=null ) { v=act; 
		if (obj.style) { 
		obj=obj.style; v=(v=='show')?'block':(v='hide')?'none':v;
		if(act.indexOf('show')!=-1&&menustr!='menuAbout')
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			obj.left=findPos(document.getElementById(tdstr))[0];
		} else {
			obj.left=findPos(document.getElementById(tdstr))[0] + 'px';
		}
		}
    obj.display=v; }    
}

var bHover='';
var secSet = null;
var activeTimer = null;

function hideDDs( sect ) { bgClear('menuTech', 'hide');
	bgClear('menuService','hide');
	bgClear('menuProf','hide');
	bgClear('menuNews','hide');
	bgClear('menuAbout','hide');
	bgClear('menuContact','hide');
}
function hidemenu( menustr ) { bgClear(sect,'hide');hideDDs(sect); }
function hideDD(sect) {
	bgClear(sect,'hide');hideDDs(sect);
}

function setDDTimeout(sect){
	if (secSet != null) window.clearTimeout(secSet);
	secSet = window.setTimeout('hideDD("' + sect + '")',500);
}

function findDiv(n, d) { 
	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=findDiv(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function setDD(sect, windowStatusVal, bshow) {
	hideDDs(sect);
	if ((bHover==windowStatusVal)||(bshow)){
		bgClear(sect,'show');
		if (secSet != null) window.clearTimeout(secSet);		
		hideElement('SELECT', document.getElementById(sect)); 
	}
}
function mainovr(div, status)
{
	if(is_safari){
		bHover=status;window.status=status;setDD(div,status,false);}
	else{
		bHover=status;window.status=status;setTimeout('setDD(\'' + div + '\', \'' + status + '\', false)',400);}
}
function mainout(div) { bHover='';window.status='';setDDTimeout(div); }
function menuovr(div, link, item) { window.status=link;item.style.backgroundColor="#CCCCCC";setDD(div,'',true); }
function menuout(div, item) { setDDTimeout(div); item.style.backgroundColor="#F0F0F0"; }
function hideElement( elmID, overDiv ) {
  if(document.all) {
    for(i = 0; i < document.all.tags( elmID ).length; i++) {
      obj = document.all.tags( elmID )[i];
      if(!obj || !obj.offsetParent) continue;
      // Find the element's offsetTop and offsetLeft relative to the BODY tag. '
      objLeft   = obj.offsetLeft - overDiv.offsetParent.offsetLeft;
      objTop    = obj.offsetTop;
      objParent = obj.offsetParent;
      while(objParent.tagName.toUpperCase() != 'BODY') {
        objLeft  += objParent.offsetLeft;
        objTop   += objParent.offsetTop;
        objParent = objParent.offsetParent;}
      objHeight = obj.offsetHeight;
      objWidth  = obj.offsetWidth;
      if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
      else if((overDiv.offsetParent.offsetTop + overDiv.offsetHeight + 20) <= objTop);
      else if(overDiv.offsetTop >= eval(objTop + objHeight));
      else if(overDiv.offsetLeft >= eval(objLeft + objWidth));
      else {
        obj.style.display = 'none';
      }
    }
  }
}

function showElement(elmID) {
  if(document.all) {
    for(i = 0; i < document.all.tags( elmID ).length; i++) {
      obj = document.all.tags(elmID)[i];
      if(!obj || !obj.offsetParent) continue;
      obj.style.visibility = '';
    }
  }
}
function startdiv(idval,w){
	var s = document.write ('<div id="'+idval+'" class="divstyle"><table width="'+w+'" border="0" cellpadding="0" cellspacing="0">');
}
function enddiv(){
	var s = document.write ("</table></div>");
}
function bi(link,div,name){
	var s = document.write ("<tr><td onClick=\"lnk('"+link+"');\" onMouseOver=\"menuovr('"+div+"','"+pn(name)+"',this);\" onMouseOut=\"menuout('"+div+"',this);\" class=\"nav2\">"+name+"</td></tr>");
}
function pn(name){
	var s=name;if(s.indexOf("<")>0) {return(s.slice(0,s.indexOf("<")-1));}return(s);
}
function lnk(link){
	internal_clicked = true;
	window.open(link,'_self');
}

function getdropdowns(){
	var dn = 'menuTech';
	startdiv(dn,'160');
	bi('power4ev.html',dn,'Power Storage For EVs');
	bi('mglbattery.html',dn,'Li-Battery Specifications');
	bi('ibp.html',dn,'DPS&rsquo;s IBP technology');
	bi('product.html',dn,'Product Specification');
	bi('support.html',dn,'Service');
	enddiv(); 

	var dn = 'menuProf';
	startdiv(dn,'160');
	bi('aboutus.html',dn,'Company');
	bi('coreteam.html',dn,'Management');
	bi('philosophy.html',dn,'Philosophy');
	bi('director.html',dn,'Directors');
	bi('advisors.html',dn,'Advisors');
	// bi('#',dn,'Investors');
	enddiv(); 

	var dn = 'menuService';
	startdiv(dn,'160');
	bi('links.html',dn,'Related Links');
	bi('glossary.html',dn,'Glossary');
	enddiv(); 

	var dn = 'menuNews';
	startdiv(dn,'160');
	bi('news_0.html',dn,'SSTE Agreement');
	bi('newsqel.html',dn,'Q-Electric and MOU');
	bi('newscit.html',dn,'CITIC Guoan MGL and MOU');
	bi('newsdyn.html',dn,'Dynasty EV LOI');
	bi('newsqsc.html',dn,'QSC-S&T Park Agreement');
	enddiv(); 

	var dn = 'menuAbout';
	startdiv(dn,'160');
	bi('aboutus.html',dn,'Company');
	bi('coreteam.html',dn,'Management');
	bi('philosophy.html',dn,'Philosophy');
	bi('director.html',dn,'Directors');
	bi('advisors.html',dn,'Advisors');
	// bi('#',dn,'Investors');
	// bi('contactus.html',dn,'Contact Us');
	// bi('careers.html',dn,'Career');
	// bi('links.html',dn,'Industry Links');
	// bi('maps.html',dn,'Map Direction');
	enddiv(); 

	var dn = 'menuContact';
	startdiv(dn,'160');
	bi('contactus.html',dn,'Contact Us');
	bi('careers.html',dn,'Career');
	bi('maps.html',dn,'Map Direction');
	enddiv(); 
}

function tipshow( intPlaceX, intPlaceY, strContent, bShow ) {
	var divobj = document.getElementById('tipDiV');
	divobj.innerHtml='<table border="1" cellspacing="0" cellpadding="0" width="30" height="20">'
		+ '<tr><td>'+ strContent +'</td></tr>'
		+ '</table>';

	if(bShow) divobj.style.display="block";
	else divobj.style.display="none";
}

function checkpage()
{
	var techpages = "tech;power4ev;mglbattery;scalebattery;scalbat_1;scalbat_2;scalbat_3;scalbat_4;scalbat_5;";
	var profpages = "aboutus;coreteam;director;contactus;maps";
	var servpages = "product;support";
	myurl = location.href;
	mySub1 = "/";
	mySub2 = ".html";
	myVar = myurl.lastIndexOf(mySub1) == -1?"":myurl.substring(myurl.lastIndexOf(mySub1)+1, myurl.length);
	myText = myVar.lastIndexOf(mySub2) == -1?"":myVar.substring(0, myVar.lastIndexOf(mySub2));

	if(myVar.length==0 || myText.length==0)
    {
    }
	else if(techpages.indexOf(myText)!=-1)
	{
		document.getElementById('tech').style.display='block';
	}
	else if(profpages.indexOf(myText)!=-1)
	{
		document.getElementById('prof').style.display='block';
	}
	else if(servpages.indexOf(myText)!=-1)
	{
		document.getElementById('serv').style.display='block';
	}
}
