var _debug = true;
var javaScriptLastSentData = '';
var javaScriptState = '';
var requestUrl = "queryData.aspx";
var queryString = "Questions on this page ? "
var sendString = "Send"
var messString = "Questions on this page ? "
explorer = (document.all) ? true:false;
netscape = (document.layers) ? true:false;
dom = (document.getElementById) ? true:false;


//----------------popup variables---------------

var left = Math.round(screen.availWidth/2)
var top = Math.round(screen.availHeight/2)
var windowCount = 0


function getHttpObject(handler)
{
//      alert( 'start get http');
   /* @cc_on @ */
   /* @if (@_jscript_version >= 5) */
   try 
   {
      //alert( 'going v5 to create objecte' + url);
        //xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
        xmlhttp = new XMLHttpRequest();
         xmlhttp.onreadystatechange = handler
   }
   catch (e) 
   {
      try
      {
         xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
         xmlhttp.onreadystatechange = handler
			
      }
      catch (E)
      {
       alert( 'sjm xmlhttp fail' + url);
         xmlhttp = false;
      }
   }
/*   @else  */
//	  alert('else condition')
/*   @end */
   if (!xmlhttp && typeof XMLHttpRequest!='undefined')
   {			
      try 
      {
//      alert( 'doing new ');
         xmlhttp = new XMLHttpRequest();
         xmlhttp.onreadystatechange = handler
      }
      catch(e)
      {
//      alert( 'catch3');
         xmlhttp=false;
      }
   }
//      alert( 'try other');
   if (!xmlhttp && window.createRequest) 
   {
      try 
      {
         xmlhttp = window.createRequest();
         xmlhttp.onreadystatechange = handler
      }
      catch (e) 
      {
         xmlhttp=false;
      }
   }
}
function submitForm()
{
	var _form;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
	{
		theform = document.Form1;
	}
	else
	{
		theform = document.forms["Form1"];
	}
	theform.submit();
}
function sendQuery(data)
{ 
   var len =  data.indexOf(':');
   javaScriptLastSentData = data;
   //alert('sendQuery last sent data is ' + javaScriptLastSentData + ' data =' + data);

   var url = requestUrl;
   if (data.length > 0)
   {
	     url = url + '?d=' + data;
   }
  
   if (_debug == true)
   {
      //alert("sendQuery url=" + url +  ',data=' + data);
   }
   getHttpObject(xmlHandleResponse);
   //alert('sending' + url);
   //alert ('url is ' + url);
   sendXmlHttp(url); 
   
   //alert('trace data is ' + data);
   
} 
function xmlHandleResponse() 
{
   
   if (xmlhttp.readyState == 4 || xmlhttp.readyState == 'complete')
   { 
//Get results from callback 
      var str = xmlhttp.responseText; 
      var resp = document.getElementById('response_txt');
      //alert("response=" + str);
      resp.value = str;
      
      //resp.style.visibility = 'visible';
   }
}
// XMLHttp send Xml Http request 


function sendXmlHttp(url) 
{
//alert( 'sending  ' + url)
   if(!xmlhttp)
   {
      alert('send fail');
      return;
   }
  //alert('sjm - going to open xmlhttp ' + url);
   //alert( 'going to open' + url)
   xmlhttp.open('GET', url, true);
   //alert('sjm - going to send xmlhttp ' + url);
   xmlhttp.send(null); 
} 

function processResponse(result,tag)
{
   //alert('processResponse ' + tag);
   if (tag == 'doState')
   {
      doState(result,tag);
   }
   else if (tag == 'handleUnitType')
   {
       if (result.length > 0)
       {
          handleUnitType(result,'numerator');
       }
   }
   
   
   validateApply("0");
    
}

 

    function doQ(){
        //alert('hello this is doQ');
    }
    function showQuery(show,all){
        var place = document.getElementById('queryPlace')
        var email = document.getElementById('email_txt');
        var cancel = document.getElementById('cancel_btn');
        var query = document.getElementById('query_btn');
        var mess = document.getElementById('mess_txt');
        var info = document.getElementById('info_txt');
        //var emailLab = document.getElementById('email_lab');
        var resp = document.getElementById('response_txt');
        var nme = document.getElementById('nme_txt');
        var backGround = document.getElementById('queryPlace');
        if (email == null){
            return;
        }
        if (show == 0){
            place.style.visibility = 'hidden';
            place.style.display = 'none';
            email.style.visibility = 'hidden';
            mess.style.visibility = 'hidden';
            cancel.style.visibility = 'hidden';
            info.style.visibility = 'hidden';
            query.value = queryString;
            if (all != null){
                query.style.visiblity = 'visible';
            } else {
                query.value = queryString;
            }
            nme.style.visibility = 'hidden';
            //emailLab.style.visibility = 'hidden';
            //backGround.style.background = 'Transparent';
            
        } else {
            place.style.visibility = 'visible';
            place.style.display = '';
            email.style.visibility = 'visible';
            mess.style.visibility = 'visible';
            cancel.style.visibility = 'visible';
            info.style.visibility = 'visible';
            nme.style.visibility = 'visible';
            query.value = sendString;
            if (all != null){
                query.style.visiblity = 'visible';
            } else {
                //query.value = sendString;
            }
            //emailLab.style.visibility = 'visible';
            resp.style.visibility = 'hidden';
            resp.value = '';
            //backGround.style.background = queryColour;
        }
        return true;
    }
    function getPosition(obj){
       var topValue= 0,leftValue= 0;
          while(obj){
   	      leftValue+= obj.offsetLeft;
	      topValue+= obj.offsetTop;
	      obj= obj.offsetParent;
       }
       finalvalue = leftValue + ":" + topValue;
       return finalvalue;
    }
    function getScroll(obj){
       var topValue= 0,leftValue= 0;
          while(obj){
   	      leftValue+= obj.scrollLeft;
	      topValue+= obj.scrollTop;
	      obj= obj.offsetParent;
	      //if (topValue > 0){
	        //break;
	      //}
       }
       finalvalue = leftValue + ":" + topValue;
       return finalvalue;
    }
    function showInfo(show,text,obj){
        var backGround = document.getElementById('infoPlace');
        var info = document.getElementById('infoText');
        if (backGround == null || info == null){
            return;
        }
        if (show == 0){
            backGround.style.background = 'Transparent';
            info.innerText = "";
            info.style.visibility='hidden';
            info.style.display='none';
        } else {
            backGround.style.background = infoColour;
            //backGround.style.top = obj.style.top;
            //backGround.style.left = obj.style.left;
            //backGround.style.left = obj.offsetLeft + 10;
            //backGround.style.top = obj.offsetTop;
            var offset = getPosition(obj);
            var arr = offset.split(':');
            var left = parseInt(arr[0]);
            var top = parseInt(arr[1]);

            offset = getScroll(obj);
            arr = offset.split(':');
            var objLeft = parseInt(arr[0]);
            var objTop = parseInt(arr[1]);


            left+=10;
            left-=objLeft;
            top-=objTop;
            
            backGround.style.left = left + "px";
            backGround.style.top = top + "px";
            //info.innerText = backGround.style.left + ":" + backGround.style.top + " , " + obj.offsetLeft + ":" + obj.offsetTop + " , " + getPosition(obj)  + " , " + backLeft + ":" + backTop  + " , " + infoLeft + ":" + infoTop   + " , " + obj.scrollLeft + ":" + obj.scrollTop  + " , " + objLeft + ":" + objTop;
            info.innerText = text;
            info.style.visibility='visible';
            info.style.display='inline';
            
            //info.style.display='';
        }
        return true;
    }
   
    function setUrl(url){
        requestUrl = url;
    }

        var query = document.getElementById('query_btn');
    function doQuery(url){
        //alert('hello do Query');

        var query = document.getElementById('query_btn');
        var mess = document.getElementById('mess_txt');
        var temp = query.value;
        if (temp == queryString){
            showQuery(1);
        } else {
            sendQuery(mess.value);
            showQuery(0);
        }
        return true;
    }

function initialiseQuery(mess,question){
    var obj = document.getElementById('queryLink');
    if (obj != null){
        obj.style.visibility="visible";
        if (question != null && question != ""){
            obj.innerHTML = question;
        }else if (mess != null){
            obj.innerHTML = "Ask about " + mess;
        }
    }
    showQuery(0);

}


//////////////////:o) Menu code ////////////////////////////

//-->

