var starGo='', starNum=0;

function $_(v) { return(document.getElementById(v)); }
function $_S(v) { return(document.getElementById(v).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function absPos(o) { var r={x:o.offsetLeft,y:o.offsetTop}; if(o.offsetParent) { var v=absPos(o.offsetParent); r.x+=v.x; r.y+=v.y; } return(r); }
function xy(e,v) {
        if (document.documentElement) msieO=document.documentElement;
        else msieO=document.body;
        msieTop=msieO.scrollTop;
        msieLeft=msieO.scrollLeft;
        return(v?(agent('msie')?event.clientY+msieTop:e.pageY):(agent('msie')?event.clientX+msieLeft:e.pageX));
}

function starUpdate(e,o) {
        var v=parseInt($_('starUser'+starNum).innerHTML);
        starNum=o.id.substr(4);
        $_('starCurr'+starNum).title=v;
        /*
        req=new XMLHttpRequest();
        req.open('GET','/AJAX_Star_Vote.php?vote='+(v/100),false);
        req.send(null);
        */
        var el=document.getElementById('provider_rating');
        if(el) {
                el.value=v;
        }
}
function starRevert() {
        var v=parseInt($_('starCurr'+starNum).title);
        $_S('starCurr'+starNum).width=Math.round(v*84/100)+'px';
        $_('starUser'+starNum).innerHTML=(v>0?Math.round(v)+'%':'');
        $_('starUser'+starNum).style.color='#888';
        document.onmousemove='';
}
function starCurr(e,o) {

        function starMove(e) {
                var p=absPos($_('star'+starNum));
                starNum=o.id.substr(4);
                var eX=xy(e)-p.x, eY=xy(e,1)-p.y;
                if(eX<1 || eX>84 || eY<0 || eY>19) {
                        starGo='';
                        starRevert();
                } else {
                        $_S('starCurr'+starNum).width=eX+'px';
                        $_S('starUser'+starNum).color='#111';
                        $_('starUser'+starNum).innerHTML=Math.round(eX/84*100)+'%';
                }

        }

        if(!starGo) { starGo=1; document.onmousemove=starMove; }

}


function checkVals() {
        invalid=false;
        req=new Array('opttype','my_cost','my_rental','my_provider','my_speed','post_code','provider_rating');
        reqNice=new Array('Connection Type','Monthly Broadband Cost','Monthly Phone Line Rental','Current Broadband Provider','Speed','Postcode','Rate your provider');
        txtarr=new Array();
        cnt=0;
        txt="Please ensure you have entered a value for:\n";
        for(i=0;i<req.length;i++) {
                oEl=document.getElementById(req[i]);
                if(oEl) {
                if(oEl.value=='' || oEl.value=='-') {
                        invalid=true;
                        txtarr[cnt]=reqNice[i];
                        cnt++;
                }
                }
        }
        txt+=txtarr.join(', ');
        if(invalid) {
                alert(txt);
                return false;
        } else {
                return true;
        }
}

//function to slide email box into out of view
var pid = 0,
linkCnt = 0;
function run(){
   //var tab1 = document.getElementById('tab1');
   //tab1Top = tab1.style.top;
   //alert(tab1Top);
   clearTimeout(pid);
   var height = parseInt(document.getElementById("links").style.height);
   var chk=document.getElementById("my_emailme");
   if(chk.checked) {
           if( height < 40 && linkCnt < 40){
             //100 can be replaced with the desired height!
              linkCnt+=2;
              document.getElementById("links").style.height = linkCnt+'px';
              //tab1.style.top = (tab1Top + linkCnt) + 'px';
              pid=setTimeout("run();", 15);
           }
   } else {
          //if(linkCnt < 1) linkCnt=40;
          if( height > 0 && linkCnt > 0) {
              linkCnt-=2;
              document.getElementById("links").style.height = linkCnt+'px';
              //tab1.style.top = (tab1Top - linkCnt) + 'px';
              pid=setTimeout("run();", 15);
        }
   }
}
