function _gel(id){
    return document.getElementById(id);
}
function _GC(t){
   return document.createElement(t);
}

function isIE(){
      return (document.all && window.ActiveXObject && !window.opera) ? true : false;
} 

function getBodySize(){
   var bodySize = [];
   with(document.documentElement) {
    bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
    bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
   }
   return bodySize;
}

function popCoverDiv(){
   if (_gel("_cover_div")) {
      _gel("_cover_div").style.display = '';
   } else {
      var coverDiv = _GC('div');
      coverDiv.id = '_cover_div';
      var bodySize = getBodySize();
      with(coverDiv.style) {
         position = 'absolute';
         left = '0px';
         top = '0px';
         width = bodySize[0] + 'px'
         height = bodySize[1] + 'px';
         zIndex = "88";

         //for new mozilla
         opacity="1";
         //for old mozilla
         MozOpacity="1"
         //for KHTML rendering engine
         KhtmlOpacity = "1"; 
         //for IE
         filter="alpha(opacity=100)";
      }

      coverDiv.innerHTML="<div style='background:#000;opacity:0.2;filter:alpha(opacity=20);width:"+bodySize[0]+";height:"+bodySize[1]+"'></div>"

      //add a iframe to CoverDiv, for only div can't cover some objects, such as select...
      if (document.all&&navigator.userAgent.match(/msie/gi)){
         var f=document.createElement("iframe");
         f.src="";
         f.frameBorder=0;
         with(f.style){
            position="absolute";
            left="0";
            top="0";
            width= bodySize[0] + 'px';
            height=bodySize[1] + 'px';
            visibility="inherit";
            zIndex="-1";
         }
         coverDiv.appendChild(f);
      }

      document.body.appendChild(coverDiv);
   }
}

function popWin(popDiv) {
   popCoverDiv();  
   showPop(popDiv);  
   //document.body.style.overflow = "hidden";
}

var _popDiv;
function showPop(popDiv){
   _popDiv=_gel(popDiv);
   with (_popDiv.style) {
      display = '';
      position = 'absolute';
      left=(document.documentElement.clientWidth - _popDiv.clientWidth)/2 + 'px';
      top = (document.documentElement.clientHeight - _popDiv.clientHeight)/2 + 'px';
   }
   if(popDiv=="pop_terms")
      makeShadow();
}

function closePop(){
   if(!_popDiv)return;
   _popDiv.style.display = 'none';
   if(_gel("_cover_div"))
      _gel("_cover_div").style.display = 'none';
   document.body.style.overflow = '';
   _gel("loginId").focus();
   closeShadow();
}

function makeShadow(){
      //right bottom shadow border
      if(_gel("_shadow_div")){
         shadowDiv=_gel("_shadow_div");
      }else{
         shadowDiv = _GC('div');
         document.body.appendChild(shadowDiv);
         shadowDiv.id = '_shadow_div';
         shadowDiv.className='shadow';
      }
      with (shadowDiv.style) {
         display = '';
         left=(_popDiv.offsetLeft+6) + 'px';
         top =(_popDiv.offsetTop+6) + 'px';
         width=_popDiv.offsetWidth+'px';
         height=_popDiv.offsetHeight+'px';
      }

}

function closeShadow(){
   if(_gel("_shadow_div"))
      _gel("_shadow_div").style.display="none";
}

function showFaqPop(link){
   //window.open(link,"_blank");
   
   //window.status=link;
   _gel("iframe_faq").src=FAQ_ROOT+link;
   var pop=_gel("pop_faq");
   with (pop.style) {
      display = '';
      position = 'absolute';
      left='0px';
      top = (document.documentElement.clientHeight - pop.clientHeight)/2 + 'px';
   }
}

function closeFaqPop(){
   var pop=_gel("pop_faq");
   pop.style.display = 'none';
}

//auto adjust height for faq iframe 
function resizeFAQPopup(){
   var iframe = document.getElementById("iframe_faq");

   if(iframe.src=="") return;
   var bHeight = iframe.contentWindow.document.body.scrollHeight;
   var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
   var height = Math.max(bHeight, dHeight);
   iframe.height =  height;

   var pop=_gel("pop_faq");
   with (pop.style) {
      display = '';
      position = 'absolute';
      left='0px';
      top = (document.documentElement.clientHeight - pop.clientHeight)/2 + 'px';
   }

   window.status= iframe.height;

}
//window.setInterval("resizeFAQPopup()", 200);


//get rss by AjaxProxy
function getFAQbyAjax(){
   var url='http://telenav.custhelp.com/cgi-bin/telenav.cfg/php/enduser/opensearch.php?q=&&startPage=1&pagesize=5&p_pv=&p_cv=1.50&p_cats=50';
   var result=AjaxProxy.getRomoteURL(url, "");

   alert(result);
   var items=result.selectSingleNode("//channel").selectNodes("item");
   //alert(items.lenght);

   var col_size=3; //column size
  var html="<div class=\"faq_title\">Frequently Asked Questions:</div><table class=\"faq_tbl\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
  for(var i=0;i<items.length&&i<5;i++){
     var item=items[i];
     html+="<td class=\"faq_td\"><img src=\"./images/tnt_login_bullet.gif\" style=\"padding-right:6px;\"><a href=\""+item.selectSingleNode("link").text+"\" style=\"font-size:12px;\" target=\"_TeleNav_FAQ\">"+item.selectSingleNode("title").text+"</a></td>"
     if((i+1)%col_size==0)
        html+="</tr><tr>";
  }
   html+="</tr></table>";
   //alert(html);

   _gel("faq_content").innerHTML=html;

}

function showFAQList() {

   //for local test style
   //var html='<div class="faq_title">Frequently Asked Questions:</div><table class="faq_tbl" cellspacing="0" cellpadding="0"><tr><td class="faq_td"><img src="./images/tnt_login_bullet.gif" style="padding-right:6px;"><a href="http://telenav.custhelp.com/cgi-bin/telenav.cfg/php/enduser/std_adp.php?p_faqid=90&p_created=1221163821" style="font-size:12px;">Why Is My Device Not Tracking?</a></td><td class="faq_td"><img src="./images/tnt_login_bullet.gif" style="padding-right:6px;"><a href="http://telenav.custhelp.com/cgi-bin/telenav.cfg/php/enduser/std_adp.php?p_faqid=41&p_created=1219449023" style="font-size:12px;">TeleNav Track v4.0 Website Guide</a></td><td class="faq_td"><img src="./images/tnt_login_bullet.gif" style="padding-right:6px;"><a href="http://telenav.custhelp.com/cgi-bin/telenav.cfg/php/enduser/std_adp.php?p_faqid=10&p_created=1219437028" style="font-size:12px;">Stop Users From Deleting TeleNav Track On Nextel Phones</a></td></tr><tr><td class="faq_td"><img src="./images/tnt_login_bullet.gif" style="padding-right:6px;"><a href="http://telenav.custhelp.com/cgi-bin/telenav.cfg/php/enduser/std_adp.php?p_faqid=2&p_created=1218652326" style="font-size:12px;">Schedule A Training Session For TeleNav Track</a></td><td class="faq_td"><img src="./images/tnt_login_bullet.gif" style="padding-right:6px;"><a href="http://telenav.custhelp.com/cgi-bin/telenav.cfg/php/enduser/std_adp.php?p_faqid=9&p_created=1219436529" style="font-size:12px;">Stop Users From Turning Off TeleNav Track On Nextel Phones</a></td></tr></table>';
   //_gel("faq_content").innerHTML=html;
   //return ;

   if (xmlHttp.readyState==4 && xmlHttp.status==200) {
      var result = xmlHttp.responseXML;
      xmlHttp = null;
      //alert(result.xml);
      var items=result.selectSingleNode("//channel").selectNodes("item");
      //alert(items.lenght);

      var col_size=3; //column size
      var top_size=5; //top faq size
     var html="<div class=\"faq_title\">Frequently Asked Questions:</div><table class=\"faq_tbl\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
     for(var i=0;i<items.length&&i<top_size;i++){
        var item=items[i];
        html+="<td class=\"faq_td\"><img src=\"./images/tnt_login_bullet.gif\" style=\"padding-right:6px;\"><a href=\""+GetNodeValue(item.selectSingleNode("link"))+"\" style=\"font-size:12px;\" target=\"_TeleNav_FAQ\">"+GetNodeValue(item.selectSingleNode("title"))+"</a></td>"
        if((i+1)%col_size==0)
           html+="</tr><tr>";
     }
      html+="</tr></table>";
      //alert(html);

      _gel("faq_content").innerHTML=html;
   }

}

/**
 * For a text field(element), if its value is null, show the 'inlineText' in it.
 * If it is focused, remove the inlineText and if lost focus, reset the vale to 'inlineText'.
 */
function addInlineText(element, inlineText) {
   if (!element) {
      return;
   }
   var originalCss=element.className;
   if (element.value==""||element.value==inlineText) {
      element.className = " italic_font";
      element.value=inlineText;
   }
   element.onfocus=function() {
      if (element.value==inlineText) {
         element.value="";
      }
      element.className=originalCss;
   };
   element.onblur=function() {
      if (element.value==""||element.value==inlineText) {
         element.value=inlineText;
         element.className = " italic_font";
      }
   };

}
